import {
  getTopMV
} from '../../services/video'
Page({
  data: {
    videoList: [],
    offset: 0,
    hasMore: true,
  },
  onLoad() {
    // 发送网络请求
    this.fetchTopMV()
  },

  // 发送网络请求方法
  async fetchTopMV() {
    // 1.获取数据
    const res = await getTopMV(this.data.offset)
    // 2.将新数据追加到原来数据后面
    const newVideoList = [...this.data.videoList, ...res.data]
    // 3.设置全新的数据
    this.setData({
      videoList: newVideoList
    })
    this.data.offset = this.data.videoList.length
    this.data.hasMore = res.hasMore
  },

  // 监听上拉和下拉功能
  // 下拉
  onReachBottom() {
    if (!this.data.hasMore) {
      return
    }
    this.fetchTopMV()
  },
  // 上拉
  async onPullDownRefresh() {
    // 清空数据
    this.setData({
      videoList: []
    })
    this.data.offset = 0
    this.data.hasMore = true

    // 2.重新请求数据
    await this.fetchTopMV()
    // 3.停止下拉
    wx.stopPullDownRefresh()
  },
  onShareAppMessage() {
    return {
      title: 'Time Music',
      path: '/pages/main-music/main-music',
      imageUrl:''
    }
  },
  
})